<template>
	<view class="wrap">
		<view class="main" v-if="hasLoad">
			<view class="b-main">
				<text class="s-cont">{{state.content}}</text>
			</view>
			<view class="b-photos" v-if="state.photos.length > 0">
				<view class="s-item" v-for="(item, index) in state.photos" :key="index">
					<image :src="item.url" mode="widthFix" @click="onPreview(index)"></image>
				</view>
			</view>
			<view class="b-foot">
				<view class="s-info">
					<view class="s-type">{{state.type_text}}</view>
					<view class="s-state" :class="'f-state-' + state.status">{{state.status_text}}</view>
				</view>
				<view class="s-time">{{timeFormat(state.created_at)}}</view>
			</view>
			<view class="b-reply" v-if="state.status === 2">
				<text class="s-cont">{{state.reply_content}}</text>
				<view class="s-photos" v-if="state.reply_photos.length > 0">
					<view class="s-item" v-for="(item, index) in state.reply_photos" :key="index">
						<image :src="item.url" mode="widthFix" @click="onPreview(index, 'reply')"></image>
					</view>
				</view>
				<view class="s-time">回复时间：{{timeFormat(state.reply_time)}}</view>
			</view>
		</view>
		<!-- 加载中 -->
		<load-more :loadingType="loadingType" :loadingText="loadingText" :top="300"></load-more>
	</view>
</template>

<script>
	import {
		getRecordDetail
	} from '@/service/api/feedback.js'
	import mixinsAuth from '@/mixins/auth.js'
	import mixinsCommon from '@/mixins/common.js'
	export default {
		mixins: [mixinsCommon, mixinsAuth],
		data() {
			return {
				state: null,
				hasLoad: false,
				loadingType: 1,
				loadingText: ''
			}
		},
		onLoad(options) {
			this.recordId = options.id
			this.loadDetail()
		},
		methods: {
			loadDetail() {
				getRecordDetail(this.recordId).then(([err, res]) => {
					console.log('getRecordDetail', err, res)
					if (!err) {
						this.hasLoad = true
						this.loadingType = -1
						this.state = res
					} else {
						this.loadingType = 3
						this.loadingText = err.data.msg || '加载失败'
					}
				})
			},
			onPreview(index, type) {
				let photos = []
				if (type === 'reply') {
					for (let i = 0; i < this.state.reply_photos.length; i++) {
						photos.push(this.state.reply_photos[i].url)
					}
				} else {
					for (let i = 0; i < this.state.photos.length; i++) {
						photos.push(this.state.photos[i].url)
					}
				}
				uni.previewImage({
					current: index,
					urls: photos
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		padding-bottom: env(safe-area-inset-bottom);
		background: $pq-bg-color;
	}

	.wrap {
		padding: 40upx;
	}

	.b-main {
		.s-cont {
			font-size: 28upx;
			color: #333;
		}

	}

	.b-photos {
		margin-top: 30upx;
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;

		.s-item {
			margin-bottom: 20upx;
			margin-right: 20upx;
			position: relative;
			width: 210upx;

			&:nth-child(3n) {
				margin-right: 0;
			}

			image {
				width: 210upx;
			}
		}
	}

	.b-foot {
		margin-top: 30upx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.s-info {
			display: flex;
			align-items: center;

			.s-type {
				margin-right: 20upx;
				font-size: 24upx;
				padding: 5upx 15upx;
				color: #fff;
				background: #666;
				border-radius: 10upx;
			}

			.s-state {
				font-size: 26upx;
				color: #666;

				&.f-state-1 {}

				&.f-state-2 {
					color: #DA5650;
					font-weight: bold;
				}
			}
		}

		.s-time {
			font-size: 24upx;
			color: #666;
		}
	}

	.b-reply {
		margin-top: 20upx;
		background: #fff;
		padding: 20upx;
		display: flex;
		flex-direction: column;

		.s-cont {
			font-size: 28upx;
			color: #333;
		}

		.s-photos {
			margin-top: 20upx;
			display: flex;
			flex-wrap: wrap;
			justify-content: flex-start;

			.s-item {
				margin-bottom: 20upx;
				margin-right: 20upx;
				position: relative;
				width: 210upx;

				&:nth-child(3n) {
					margin-right: 0;
				}

				image {
					width: 210upx;
				}
			}
		}

		.s-time {
			margin-top: 20upx;
			font-size: 24upx;
			color: #666;
		}
	}
</style>
